$(function () {
    $("#jqGrid").jqGrid({
        url: '../socialsecuritypaydetail/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', key: true ,hidden:true},
            { label: '单位名称', name: 'unitName', index: 'unit_name'},
            { label: '姓名', name: 'name', index: 'name'},
            { label: '社保险种', name: 'socialSecurityType', index: 'social_security_type',formatter:getDictInfo},
			{ label: '身份证号', name: 'cardNo', index: 'card_no'}, 			
			{ label: '年', name: 'year', index: 'year'}, 			
			{ label: '月', name: 'month', index: 'month'}, 			
			{ label: '方式', name: 'way', index: 'way'}, 			
			{ label: '是否结转', name: 'isCarryOver', index: 'is_carry_over',formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '基数', name: 'baseNum', index: 'base_num'}, 			
			{ label: '单位比例', name: 'unitScale', index: 'unit_scale'}, 			
			{ label: '个人比例', name: 'personScale', index: 'person_scale'}, 			
			{ label: '单位应缴', name: 'unitPayable', index: 'unit_payable'}, 			
			{ label: '个人应缴', name: 'personPayable', index: 'person_payable'}, 			
			{ label: '应缴付款劳动局状态', name: 'payableState', index: 'payable_state'}, 			
			{ label: '应缴补报单位', name: 'bubaoPayableUnit', index: 'bubao_payable_unit'}, 			
			{ label: '应缴补报个人', name: 'bubaoPayablePerson', index: 'bubao_payable_person'}, 			
			{ label: '应缴补报付款状态', name: 'bubaoPayableState', index: 'bubao_payable_state'}, 			
			{ label: '应缴补差单位', name: 'balancePayableUnit', index: 'balance_payable_unit'}, 			
			{ label: '应缴补差个人', name: 'balancePayablePerson', index: 'balance_payable_person'}, 			
			{ label: '应缴补差付款状态', name: 'balancePayableState', index: 'balance_payable_state'}, 			
			{ label: '单位付款', name: 'unitPay', index: 'unit_pay'}, 			
			{ label: '个人付款', name: 'personPay', index: 'person_pay'}, 			
			{ label: '付款补报单位', name: 'bubaoPayUnit', index: 'bubao_pay_unit'}, 			
			{ label: '付款补报个人', name: 'bubaoPayPerson', index: 'bubao_pay_person'}, 			
			{ label: '付款补差单位', name: 'balancePayUnit', index: 'balance_pay_unit'}, 			
			{ label: '付款补差个人', name: 'balancePayPerson', index: 'balance_pay_person'}, 			
			{ label: '收款_单位结算', name: 'unitSettlement', index: 'unit_settlement'}, 			
			{ label: '收款_个人扣款', name: 'personDecut', index: 'person_decut'}, 			
			{ label: '收款_社保交退单位', name: 'socialSurePayRefundUnit', index: 'social_sure_pay_refund_unit'}, 			
			{ label: '收款_社保交退个人', name: 'socialSurePayRefundPerson', index: 'social_sure_pay_refund_person'}, 			
			{ label: '收款_补差单位', name: 'balanceGatheringUnit', index: 'balance_gathering_unit'}, 			
			{ label: '收款_补差个人', name: 'balanceGatheringPerson', index: 'balance_gathering_person'}, 			
			{ label: '收付差异_单位', name: 'payGetDifferUnit', index: 'pay_get_differ_unit'}, 			
			{ label: '收付差异_个人', name: 'payGetDifferPerson', index: 'pay_get_differ_person'}, 			
			{ label: '收付差异_说明', name: 'payGetDifferRemark', index: 'pay_get_differ_remark'}	,
            { label: '责任部门', name: 'responsibilitydepartment', index: 'responsibilityDepartment'},
            { label: '责任人', name: 'responsibilityperson', index: 'responsibilityPerson'}
        ],
		viewrecords: true,
        height: $(window).height()*0.8,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        //字段太多自动加载横轴滚动条
        shrinkToFit:false,
        autoScroll: false,
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		socialSecurityPayDetail: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.socialSecurityPayDetail = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.socialSecurityPayDetail.id == null ? "../socialsecuritypaydetail/save" : "../socialsecuritypaydetail/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.socialSecurityPayDetail),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../socialsecuritypaydetail/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../socialsecuritypaydetail/info/"+id, function(r){
                vm.socialSecurityPayDetail = r.socialSecurityPayDetail;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});